<?php
namespace app\admin\controller;
use app\admin\model\IndexTableModel;
use app\admin\model\JoinTableModel;
use think\Db;
use think\Request;
use app\common\model\User;
use app\common\model\UserLevel;
use app\common\validate\UserValidate;

require_once (__DIR__.'/../../../vendor/ReidsLock.class.php');
class FamemberprofitController extends Controller
{

    /**
     * 用户返利配置列表
     * User:@hang
     */
    public function index(Request $request)
    {
        $param = $request->param();
        $whehe = array();
        if (isset($param['member_id']) && !empty($param['member_id'])) {
            $whehe[] = ['a.member_id','=',$param['member_id']];
        }
        if (isset($param['me_uid']) && !empty($param['me_uid'])) {
            $whehe[] = ['a.me_uid','=',$param['me_uid']];
        }
        if (isset($param['me_phone']) && !empty($param['me_phone'])) {
            $whehe[] = ['a.me_phone','like',"%{$param['me_phone']}%"];
        }
        if (isset($param['me_nick_name']) && !empty($param['me_nick_name'])) {
            $whehe[] = ['a.me_nick_name','like',"%{$param['me_nick_name']}%"];
        }
        if (isset($param['me_czlwysp_rewards']) && $param['me_czlwysp_rewards'] != '') {
            $whehe[] = ['a.me_czlwysp_rewards','=',$param['me_czlwysp_rewards']];
        }
        if (isset($param['fmember_id']) && !empty($param['fmember_id'])) {
            $whehe[] = ['f.member_id','=',$param['fmember_id']];
        }
        if (isset($param['fme_uid']) && !empty($param['fme_uid'])) {
            $whehe[] = ['f.me_uid','=',$param['fme_uid']];
        }
        if (isset($param['fme_phone']) && !empty($param['fme_phone'])) {
            $whehe[] = ['f.me_phone','like',"%{$param['fme_phone']}%"];
        }
        if (isset($param['fme_nick_name']) && !empty($param['fme_nick_name'])) {
            $whehe[] = ['f.me_nick_name','like',"%{$param['fme_nick_name']}%"];
        }

        $Common = New Common();//只能看见自己相关的用户
        $q_member_str = $Common->getMyXmemberIdStr($this->uid);
        $wheheShow = '';
        if(!empty($q_member_str)) {
            $wheheShow = "a.member_id in($q_member_str)";
        }

        $configList = $Common->getConfigValueMore("'czjlsjbl','czjlsjblhbd','czjlssjbl','czjlssjblhbd','czjlsssjbl','czjlsssjblhbd','czjlssssjbl','czjlssssjblhbd','czjlsssssjbl','czjlsssssjblhbd','txetsybl','audiosybl','videosubl','giftsybl','txetsyblsj','audiosyblsj','videosublsj','giftsyblsj','txetsyblssj','audiosyblssj','videosublssj','giftsyblssj','txetsyblsssj','audiosyblsssj','videosublsssj','giftsyblsssj','txetsyblssssj','audiosyblssssj','videosublssssj','giftsyblssssj'");
        $data = Db::table('fa_member')
            ->alias('a')
            ->join("fa_member_rewards_bsbl b",'a.member_id = b.member_id','LEFT')
            ->join("fa_member_rewards_sjbl c",'a.member_id = c.member_id','LEFT')
            ->join("fa_member_rewards_ssjbl d",'a.member_id = d.member_id','LEFT')
            ->join("fa_member_rewards_sssjbl e",'a.member_id = e.member_id','LEFT')
            ->join("fa_member_rewards_ssssjbl f",'a.member_id = f.member_id','LEFT')
            ->join("fa_member m",'a.me_parent = m.member_id','LEFT')
            ->where($whehe)
            ->where($wheheShow)
            ->field('a.member_id,a.me_uid,a.me_phone,a.me_nick_name,a.phone_agent,a.me_img,a.me_invitation_rewards,a.me_czlwysp_rewards,
            
            b.lw as zs_lw,b.wz as zs_wz,b.yp as zs_yp,b.sp as zs_sp,
            c.cz as sj_cz,c.hbcz as sj_hbcz,c.lw as sj_lw,c.wz as sj_wz,c.yp as sj_yp,c.sp as sj_sp,
            d.cz as ssj_cz,d.hbcz as ssj_hbcz,d.lw as ssj_lw,d.wz as ssj_wz,d.yp as ssj_yp,d.sp as ssj_sp,
            e.cz as sssj_cz,e.hbcz as sssj_hbcz,e.lw as sssj_lw,e.wz as sssj_wz,e.yp as sssj_yp,e.sp as sssj_sp,
            f.cz as ssssj_cz,f.hbcz as ssssj_hbcz,f.lw as ssssj_lw,f.wz as ssssj_wz,f.yp as ssssj_yp,f.sp as ssssj_sp,
            
            a.me_parent,m.member_id as fmember_id,m.me_uid as fme_uid,m.me_nick_name as fme_nick_name')
            ->order('a.member_id desc')
            ->paginate($this->admin['per_page'],false,['query'=>request()->param()]);

        $data->each(function ($v, $k)use($configList) {
            //是否享受【充值文字音视频】奖励
            $v['me_czlwysp_rewards_word'] = $v['me_czlwysp_rewards'] == 0?'已关闭':'已开启';

            //========================================================================================
            //【女孩】自身获得文字收益
            if(is_null($v['zs_wz']) || $v['zs_wz'] == -1){
                $v['zs_wz'] = '（系统）'.$configList['txetsybl'];
            }
            //【女孩】自身获得音频收益
            if(is_null($v['zs_yp']) || $v['zs_yp'] == -1){
                $v['zs_yp'] = '（系统）'.$configList['audiosybl'];
            }
            //【女孩】自身获得视频收益
            if(is_null($v['zs_sp']) || $v['zs_sp'] == -1){
                $v['zs_sp'] = '（系统）'.$configList['videosubl'];
            }
            //【女孩】自身获得礼物收益
            if(is_null($v['zs_lw']) || $v['zs_lw'] == -1){
                $v['zs_lw'] = '（系统）'.$configList['giftsybl'];
            }

            //身为【超推】获得文字奖励比例
            if(is_null($v['sj_wz']) || $v['sj_wz'] == -1){
                $v['sj_wz'] = '（系统）'.$configList['txetsyblsj'];
            }
            //身为【超推】获得语音奖励比例
            if(is_null($v['sj_yp']) || $v['sj_yp'] == -1){
                $v['sj_yp'] = '（系统）'.$configList['audiosyblsj'];
            }
            //身为【超推】获得视频奖励比例
            if(is_null($v['sj_sp']) || $v['sj_sp'] == -1){
                $v['sj_sp'] = '（系统）'.$configList['videosublsj'];
            }
            //身为【超推】获得礼物奖励比例
            if(is_null($v['sj_lw']) || $v['sj_lw'] == -1){
                $v['sj_lw'] = '（系统）'.$configList['giftsyblsj'];
            }

            //身为【运营】获得文字奖励比例
            if(is_null($v['ssj_wz']) || $v['ssj_wz'] == -1){
                $v['ssj_wz'] = '（系统）'.$configList['txetsyblssj'];
            }
            //身为【运营】获得语音奖励比例
            if(is_null($v['ssj_yp']) || $v['ssj_yp'] == -1){
                $v['ssj_yp'] = '（系统）'.$configList['audiosyblssj'];
            }
            //身为【运营】获得视频奖励比例
            if(is_null($v['ssj_sp']) || $v['ssj_sp'] == -1){
                $v['ssj_sp'] = '（系统）'.$configList['videosublssj'];
            }
            //身为【运营】获得礼物奖励比例
            if(is_null($v['ssj_lw']) || $v['ssj_lw'] == -1){
                $v['ssj_lw'] = '（系统）'.$configList['giftsyblssj'];
            }

            //身为【产品】获得文字奖励比例
            if(is_null($v['sssj_wz']) || $v['sssj_wz'] == -1){
                $v['sssj_wz'] = '（系统）'.$configList['txetsyblsssj'];
            }
            //身为【产品】获得语音奖励比例
            if(is_null($v['sssj_yp']) || $v['sssj_yp'] == -1){
                $v['sssj_yp'] = '（系统）'.$configList['audiosyblsssj'];
            }
            //身为【产品】获得视频奖励比例
            if(is_null($v['sssj_sp']) || $v['sssj_sp'] == -1){
                $v['sssj_sp'] = '（系统）'.$configList['videosublsssj'];
            }
            //身为【产品】获得礼物奖励比例
            if(is_null($v['sssj_lw']) || $v['sssj_lw'] == -1){
                $v['sssj_lw'] = '（系统）'.$configList['giftsyblsssj'];
            }
            //========================================================================================

            //身为【女孩】获得充值奖励（扫码绑定）
            if(is_null($v['sj_cz']) || $v['sj_cz'] == -1){
                $v['sj_cz'] = '（系统）'.$configList['czjlsjbl'];
            }
            //身为【女孩】获得充值奖励（VIP绑定）
            if(is_null($v['sj_hbcz']) || $v['sj_hbcz'] == -1){
                $v['sj_hbcz'] = '（系统）'.$configList['czjlsjblhbd'];
            }

            //身为【超推】获得充值奖励（扫码绑定）
            if(is_null($v['ssj_cz']) || $v['ssj_cz'] == -1){
                $v['ssj_cz'] = '（系统）'.$configList['czjlssjbl'];
            }
            //身为【超推】获得充值奖励（VIP绑定）
            if(is_null($v['ssj_hbcz']) || $v['ssj_hbcz'] == -1){
                $v['ssj_hbcz'] = '（系统）'.$configList['czjlssjblhbd'];
            }

            //身为【运营】获得充值奖励（扫码绑定）
            if(is_null($v['sssj_cz']) || $v['sssj_cz'] == -1){
                $v['sssj_cz'] = '（系统）'.$configList['czjlsssjbl'];
            }
            //身为【运营】获得充值奖励（VIP绑定）
            if(is_null($v['sssj_hbcz']) || $v['sssj_hbcz'] == -1){
                $v['sssj_hbcz'] = '（系统）'.$configList['czjlsssjblhbd'];
            }

            //身为【产品】获得充值奖励（扫码绑定）
            if(is_null($v['ssssj_cz']) || $v['ssssj_cz'] == -1){
                $v['ssssj_cz'] = '（系统）'.$configList['czjlssssjbl'];
            }
            //身为【产品】获得充值奖励（VIP绑定）
            if(is_null($v['ssssj_hbcz']) || $v['ssssj_hbcz'] == -1){
                $v['ssssj_hbcz'] = '（系统）'.$configList['czjlssssjblhbd'];
            }

            return $v;
        });
        //关键词，排序等赋值
        $this->assign($request->get());
        $this->assign([
            'data'  => $data,
            'page'  => $data->render(),
            'total' => $data->total(),
        ]);
        return $this->fetch();
    }

    /**
     * 关闭【充值文字音视频】奖励
     * User:@hang
     */
    public function disable($id)
    {
        $result = Db::table('fa_member')->whereIn('member_id', $id)->update(['me_czlwysp_rewards' => 0]);
        return $result ? admin_success('操作成功', URL_RELOAD) : admin_error();
    }

    /**
     * 开启【充值文字音视频】奖励
     * User:@hang
     */
    public function enable($id)
    {
        $result = Db::table('fa_member')->whereIn('member_id', $id)->update(['me_czlwysp_rewards' => 1]);
        return $result ? admin_success('操作成功', URL_RELOAD) : admin_error();
    }

    /**
     * 批量关闭【充值文字音视频】奖励
     * User:@hang
     */
    public function pldisable($id)
    {
        $result = Db::table('fa_member')->whereIn('member_id', $id)->update(['me_czlwysp_rewards' => 0]);
        return $result ? admin_success('操作成功', URL_RELOAD) : admin_error();
    }

    /**
     * 批量开启【充值文字音视频】奖励
     * User:@hang
     */
    public function plenable($id)
    {
        $result = Db::table('fa_member')->whereIn('member_id', $id)->update(['me_czlwysp_rewards' => 1]);
        return $result ? admin_success('操作成功', URL_RELOAD) : admin_error();
    }


    /**
     * 配置用户返利比例
     * User:@hang
     */
    public function allocationratio($id)
    {
        $Common = New Common();
        $configList = $Common->getConfigValueMore("'czjlsjbl','czjlsjblhbd','czjlssjbl','czjlssjblhbd','czjlsssjbl','czjlsssjblhbd','czjlssssjbl','czjlssssjblhbd','czjlsssssjbl','czjlsssssjblhbd','txetsybl','audiosybl','videosubl','giftsybl','txetsyblsj','audiosyblsj','videosublsj','giftsyblsj','txetsyblssj','audiosyblssj','videosublssj','giftsyblssj','txetsyblsssj','audiosyblsssj','videosublsssj','giftsyblsssj','txetsyblssssj','audiosyblssssj','videosublssssj','giftsyblssssj'");

        $data = Db::table('fa_member')
            ->alias('a')
            ->join("fa_member_rewards_bsbl b",'a.member_id = b.member_id','LEFT')
            ->join("fa_member_rewards_sjbl c",'a.member_id = c.member_id','LEFT')
            ->join("fa_member_rewards_ssjbl d",'a.member_id = d.member_id','LEFT')
            ->join("fa_member_rewards_sssjbl e",'a.member_id = e.member_id','LEFT')
            ->join("fa_member_rewards_ssssjbl f",'a.member_id = f.member_id','LEFT')
            ->where("a.member_id = '{$id}'")
            ->field('a.member_id,a.me_uid,a.me_phone,a.me_nick_name,a.phone_agent,a.me_img,a.me_invitation_rewards,a.me_czlwysp_rewards,
            
            b.lw as zs_lw,b.wz as zs_wz,b.yp as zs_yp,b.sp as zs_sp,
            c.cz as sj_cz,c.hbcz as sj_hbcz,c.lw as sj_lw,c.wz as sj_wz,c.yp as sj_yp,c.sp as sj_sp,
            d.cz as ssj_cz,d.hbcz as ssj_hbcz,d.lw as ssj_lw,d.wz as ssj_wz,d.yp as ssj_yp,d.sp as ssj_sp,
            e.cz as sssj_cz,e.hbcz as sssj_hbcz,e.lw as sssj_lw,e.wz as sssj_wz,e.yp as sssj_yp,e.sp as sssj_sp,
            f.cz as ssssj_cz,f.hbcz as ssssj_hbcz,f.lw as ssssj_lw,f.wz as ssssj_wz,f.yp as ssssj_yp,f.sp as ssssj_sp,
            
            a.me_parent')
            ->find();

        //是否享受【充值文字音视频】奖励
        $data['me_czlwysp_rewards_word'] = $data['me_czlwysp_rewards'] == 0?'不奖励':'奖励';
        $adminid = $this->uid;
        //只有超管能看全部手机号
        if($adminid != 1){
            $data['me_phone'] = hide_phone_number($data['me_phone']);
        }

        //自身获得文字收益
        $data['zs_wz_word'] = $data['zs_wz'];
        if(is_null($data['zs_wz']) || $data['zs_wz'] == -1){
            $data['zs_wz'] = '-1';
            $data['zs_wz_word'] = '（系统）'.$configList['txetsybl'];
        }
        //自身获得音频收益
        $data['zs_yp_word'] = $data['zs_yp'];
        if(is_null($data['zs_yp']) || $data['zs_yp'] == -1){
            $data['zs_yp'] = '-1';
            $data['zs_yp_word'] = '（系统）'.$configList['audiosybl'];
        }
        //自身获得视频收益
        $data['zs_sp_word'] = $data['zs_sp'];
        if(is_null($data['zs_sp']) || $data['zs_sp'] == -1){
            $data['zs_sp'] = '-1';
            $data['zs_sp_word'] = '（系统）'.$configList['videosubl'];
        }
        //自身获得礼物收益
        $data['zs_lw_word'] = $data['zs_lw'];
        if(is_null($data['zs_lw']) || $data['zs_lw'] == -1){
            $data['zs_lw'] = '-1';
            $data['zs_lw_word'] = '（系统）'.$configList['giftsybl'];
        }

        //身为【超推】获得文字奖励比例
        $data['sj_wz_word'] = $data['sj_wz'];
        if(is_null($data['sj_wz']) || $data['sj_wz'] == -1){
            $data['sj_wz'] = '-1';
            $data['sj_wz_word'] = '（系统）'.$configList['txetsyblsj'];
        }
        ///身为【超推】获得语音奖励比例
        $data['sj_yp_word'] = $data['sj_yp'];
        if(is_null($data['sj_yp']) || $data['sj_yp'] == -1){
            $data['sj_yp'] = '-1';
            $data['sj_yp_word'] = '（系统）'.$configList['audiosyblsj'];
        }
        //身为【超推】获得视频奖励比例
        $data['sj_sp_word'] = $data['sj_sp'];
        if(is_null($data['sj_sp']) || $data['sj_sp'] == -1){
            $data['sj_sp'] = '-1';
            $data['sj_sp_word'] = '（系统）'.$configList['videosublsj'];
        }
        //身为【超推】获得礼物奖励比例
        $data['sj_lw_word'] = $data['sj_lw'];
        if(is_null($data['sj_lw']) || $data['sj_lw'] == -1){
            $data['sj_lw'] = '-1';
            $data['sj_lw_word'] = '（系统）'.$configList['giftsyblsj'];
        }

        //身为【运营】获得文字奖励比例
        $data['ssj_wz_word'] = $data['ssj_wz'];
        if(is_null($data['ssj_wz']) || $data['ssj_wz'] == -1){
            $data['ssj_wz'] = '-1';
            $data['ssj_wz_word'] = '（系统）'.$configList['txetsyblssj'];
        }
        ///身为【运营】获得语音奖励比例
        $data['ssj_yp_word'] = $data['ssj_yp'];
        if(is_null($data['ssj_yp']) || $data['ssj_yp'] == -1){
            $data['ssj_yp'] = '-1';
            $data['ssj_yp_word'] = '（系统）'.$configList['audiosyblssj'];
        }
        //身为【运营】获得视频奖励比例
        $data['ssj_sp_word'] = $data['ssj_sp'];
        if(is_null($data['ssj_sp']) || $data['ssj_sp'] == -1){
            $data['ssj_sp'] = '-1';
            $data['ssj_sp_word'] = '（系统）'.$configList['videosublssj'];
        }
        //身为【运营】获得礼物奖励比例
        $data['ssj_lw_word'] = $data['ssj_lw'];
        if(is_null($data['ssj_lw']) || $data['ssj_lw'] == -1){
            $data['ssj_lw'] = '-1';
            $data['ssj_lw_word'] = '（系统）'.$configList['giftsyblssj'];
        }

        //身为【产品】获得文字奖励比例
        $data['sssj_wz_word'] = $data['sssj_wz'];
        if(is_null($data['sssj_wz']) || $data['sssj_wz'] == -1){
            $data['sssj_wz'] = '-1';
            $data['sssj_wz_word'] = '（系统）'.$configList['txetsyblsssj'];
        }
        ///身为【产品】获得语音奖励比例
        $data['sssj_yp_word'] = $data['sssj_yp'];
        if(is_null($data['sssj_yp']) || $data['sssj_yp'] == -1){
            $data['sssj_yp'] = '-1';
            $data['sssj_yp_word'] = '（系统）'.$configList['audiosyblsssj'];
        }
        //身为【产品】获得视频奖励比例
        $data['sssj_sp_word'] = $data['sssj_sp'];
        if(is_null($data['ssj_sp']) || $data['ssj_sp'] == -1){
            $data['sssj_sp'] = '-1';
            $data['sssj_sp_word'] = '（系统）'.$configList['videosublsssj'];
        }
        //身为【产品】获得礼物奖励比例
        $data['sssj_lw_word'] = $data['sssj_lw'];
        if(is_null($data['sssj_lw']) || $data['sssj_lw'] == -1){
            $data['sssj_lw'] = '-1';
            $data['sssj_lw_word'] = '（系统）'.$configList['giftsyblsssj'];
        }

        //=========================================================================================================================


        //身为【女孩】获得充值奖励（扫码绑定）
        $data['sj_cz_word'] = $data['sj_cz'];
        if(is_null($data['sj_cz']) || $data['sj_cz'] == -1){
            $data['sj_cz'] = '-1';
            $data['sj_cz_word'] = '（系统）'.$configList['czjlsjbl'];
        }
        //身为【女孩】获得充值奖励（VIP绑定）
        $data['sj_hbcz_word'] = $data['sj_hbcz'];
        if(is_null($data['sj_hbcz']) || $data['sj_hbcz'] == -1){
            $data['sj_hbcz'] = '-1';
            $data['sj_hbcz_word'] = '（系统）'.$configList['czjlsjblhbd'];
        }

        //身为【超推】获得充值奖励（扫码绑定）
        $data['ssj_cz_word'] = $data['ssj_cz'];
        if(is_null($data['ssj_cz']) || $data['ssj_cz'] == -1){
            $data['ssj_cz'] = '-1';
            $data['ssj_cz_word'] = '（系统）'.$configList['czjlssjbl'];
        }
        //身为【超推】获得充值奖励（VIP绑定）
        $data['ssj_hbcz_word'] = $data['ssj_hbcz'];
        if(is_null($data['ssj_hbcz']) || $data['ssj_hbcz'] == -1){
            $data['ssj_hbcz'] = '-1';
            $data['ssj_hbcz_word'] = '（系统）'.$configList['czjlssjblhbd'];
        }

        //身为【运营】获得充值奖励（扫码绑定）
        $data['sssj_cz_word'] = $data['sssj_cz'];
        if(is_null($data['sssj_cz']) || $data['sssj_cz'] == -1){
            $data['sssj_cz'] = '-1';
            $data['sssj_cz_word'] = '（系统）'.$configList['czjlsssjbl'];
        }
        //身为【运营】获得充值奖励（VIP绑定）
        $data['sssj_hbcz_word'] = $data['sssj_hbcz'];
        if(is_null($data['sssj_hbcz']) || $data['sssj_hbcz'] == -1){
            $data['sssj_hbcz'] = '-1';
            $data['sssj_hbcz_word'] = '（系统）'.$configList['czjlsssjblhbd'];
        }

        //身为【产品】获得充值奖励（扫码绑定）
        $data['ssssj_cz_word'] = $data['ssssj_cz'];
        if(is_null($data['ssssj_cz']) || $data['ssssj_cz'] == -1){
            $data['ssssj_cz'] = '-1';
            $data['ssssj_cz_word'] = '（系统）'.$configList['czjlssssjbl'];
        }
        //身为【产品】获得充值奖励（VIP绑定）
        $data['ssssj_hbcz_word'] = $data['ssssj_hbcz'];
        if(is_null($data['ssssj_hbcz']) || $data['ssssj_hbcz'] == -1){
            $data['ssssj_hbcz'] = '-1';
            $data['ssssj_hbcz_word'] = '（系统）'.$configList['czjlssssjblhbd'];
        }

        $this->assign([
            'data' => $data,
            'member_id' => $id,
        ]);
        return $this->fetch();
    }


    /**
     * 确认配置用户返利比例
     * User:@hang
     */
    public function actionallocationratio()
    {
        $member_id = input("member_id");

        $data['zs_wz'] = $zs_wz = input("zs_wz");
        $data['zs_sp'] = $zs_sp = input("zs_sp");
        $data['zs_yp'] = $zs_yp = input("zs_yp");
        $data['zs_lw'] = $zs_lw = input("zs_lw");
        $data['sj_wz'] = $sj_wz = input("sj_wz");
        $data['sj_yp'] = $sj_yp = input("sj_yp");
        $data['sj_sp'] = $sj_sp = input("sj_sp");
        $data['sj_lw'] = $sj_lw = input("sj_lw");
        $data['ssj_wz'] = $ssj_wz = input("ssj_wz");
        $data['ssj_yp'] = $ssj_yp = input("ssj_yp");
        $data['ssj_sp'] = $ssj_sp = input("ssj_sp");
        $data['ssj_lw'] = $ssj_lw = input("ssj_lw");
        $data['sssj_wz'] = $sssj_wz = input("sssj_wz");
        $data['sssj_yp'] = $sssj_yp = input("sssj_yp");
        $data['sssj_sp'] = $sssj_sp = input("sssj_sp");
        $data['sssj_lw'] = $sssj_lw = input("sssj_lw");
        $data['sj_cz'] = $sj_cz = input("sj_cz");
        $data['sj_hbcz'] = $sj_hbcz = input("sj_hbcz");
        $data['ssj_cz'] = $ssj_cz = input("ssj_cz");
        $data['ssj_hbcz'] = $ssj_hbcz = input("ssj_hbcz");
        $data['sssj_cz'] = $sssj_cz = input("sssj_cz");
        $data['sssj_hbcz'] = $sssj_hbcz = input("sssj_hbcz");
        $data['ssssj_cz'] = $ssssj_cz = input("ssssj_cz");
        $data['ssssj_hbcz'] = $ssssj_hbcz = input("ssssj_hbcz");

        //操作上锁
        $Redis_Lock = new \Redislock();
        $otc_sell_key = 'lock:actionallocationratio';    // 定义锁标识
        $is_lock = $Redis_Lock->lock($otc_sell_key, 15);    // 获取锁
        //解锁失败
        if (!$is_lock) {
            return admin_error('操作频繁，请稍后再试！',URL_CLOSE_REFRESH);
        }

        foreach ($data as $k=>$v){
            if(!is_numeric($v)){
                $Redis_Lock->unlock($otc_sell_key);    //释放锁
                return admin_error('请输入正确的配置信息',URL_CLOSE_REFRESH);
            }else{
                if($v != -1){
                    if(getFloatLength($v) > 0){
                        $Redis_Lock->unlock($otc_sell_key);    //释放锁
                        return admin_error('比例配置不可有小数',URL_CLOSE_REFRESH);
                    }
                    if($v > 40 || $v < -1){
                        $Redis_Lock->unlock($otc_sell_key);    //释放锁
                        return admin_error('比例配置不可大于40（-1为系统值，否则必须大于等于0，小于等于40）',URL_CLOSE_REFRESH);
                    }
                }
            }
        }

        $ctime = time();
        $IndexTableModel = New IndexTableModel();
        Db::startTrans();

        if($zs_lw == -1 && $zs_wz == -1 && $zs_yp == -1 && $zs_sp == -1){
            $IndexTableModel->delOne('fa_member_rewards_bsbl',"`member_id` = '{$member_id}'");
        }else{
            $zsInfo = $IndexTableModel->getFind('fa_member_rewards_bsbl',"`member_id` = '{$member_id}'",'id');
            if(empty($zsInfo)){
                $IndexTableModel->addInfo('fa_member_rewards_bsbl',array('member_id'=>$member_id,'lw'=>$zs_lw,'wz'=>$zs_wz,'yp'=>$zs_yp,'sp'=>$zs_sp,'add_time'=>$ctime));
            }else{
                $IndexTableModel->editInfo('fa_member_rewards_bsbl',"`member_id` = '{$member_id}'",array('lw'=>$zs_lw,'wz'=>$zs_wz,'yp'=>$zs_yp,'sp'=>$zs_sp,'add_time'=>$ctime));
            }
        }


        if($sj_cz == -1 && $sj_hbcz == -1  && $sj_wz == -1 && $sj_yp == -1 && $sj_sp == -1 && $sj_lw == -1){
            $IndexTableModel->delOne('fa_member_rewards_sjbl',"`member_id` = '{$member_id}'");
        }else{
            $sjInfo = $IndexTableModel->getFind('fa_member_rewards_sjbl',"`member_id` = '{$member_id}'",'id');
            if(empty($sjInfo)){
                $IndexTableModel->addInfo('fa_member_rewards_sjbl',array('member_id'=>$member_id,'cz'=>$sj_cz,'hbcz'=>$sj_hbcz,'lw'=>$sj_lw,'wz'=>$sj_wz,'yp'=>$sj_yp,'sp'=>$sj_sp,'add_time'=>$ctime));
            }else{
                $IndexTableModel->editInfo('fa_member_rewards_sjbl',"`member_id` = '{$member_id}'",array('cz'=>$sj_cz,'hbcz'=>$sj_hbcz,'lw'=>$sj_lw,'wz'=>$sj_wz,'yp'=>$sj_yp,'sp'=>$sj_sp,'add_time'=>$ctime));
            }
        }


        if($ssj_cz == -1 && $ssj_hbcz == -1  && $ssj_wz == -1 && $ssj_yp == -1 && $ssj_sp == -1 && $ssj_lw == -1){
            $IndexTableModel->delOne('fa_member_rewards_ssjbl',"`member_id` = '{$member_id}'");
        }else{
            $sjInfo = $IndexTableModel->getFind('fa_member_rewards_ssjbl',"`member_id` = '{$member_id}'",'id');
            if(empty($sjInfo)){
                $IndexTableModel->addInfo('fa_member_rewards_ssjbl',array('member_id'=>$member_id,'cz'=>$ssj_cz,'hbcz'=>$ssj_hbcz,'lw'=>$ssj_lw,'wz'=>$ssj_wz,'yp'=>$ssj_yp,'sp'=>$ssj_sp,'add_time'=>$ctime));
            }else{
                $IndexTableModel->editInfo('fa_member_rewards_ssjbl',"`member_id` = '{$member_id}'",array('cz'=>$ssj_cz,'hbcz'=>$ssj_hbcz,'lw'=>$ssj_lw,'wz'=>$ssj_wz,'yp'=>$ssj_yp,'sp'=>$ssj_sp,'add_time'=>$ctime));
            }
        }


        if($sssj_cz == -1 && $sssj_hbcz == -1  && $sssj_wz == -1 && $sssj_yp == -1 && $sssj_sp == -1 && $sssj_lw == -1){
            $IndexTableModel->delOne('fa_member_rewards_sssjbl',"`member_id` = '{$member_id}'");
        }else{
            $sjInfo = $IndexTableModel->getFind('fa_member_rewards_sssjbl',"`member_id` = '{$member_id}'",'id');
            if(empty($sjInfo)){
                $IndexTableModel->addInfo('fa_member_rewards_sssjbl',array('member_id'=>$member_id,'cz'=>$sssj_cz,'hbcz'=>$sssj_hbcz,'lw'=>$sssj_lw,'wz'=>$sssj_wz,'yp'=>$sssj_yp,'sp'=>$sssj_sp,'add_time'=>$ctime));
            }else{
                $IndexTableModel->editInfo('fa_member_rewards_sssjbl',"`member_id` = '{$member_id}'",array('cz'=>$sssj_cz,'hbcz'=>$sssj_hbcz,'lw'=>$sssj_lw,'wz'=>$sssj_wz,'yp'=>$sssj_yp,'sp'=>$sssj_sp,'add_time'=>$ctime));
            }
        }


        if($ssssj_cz == -1 && $ssssj_hbcz == -1){
            $IndexTableModel->delOne('fa_member_rewards_ssssjbl',"`member_id` = '{$member_id}'");
        }else{
            $sjInfo = $IndexTableModel->getFind('fa_member_rewards_ssssjbl',"`member_id` = '{$member_id}'",'id');
            if(empty($sjInfo)){
                $IndexTableModel->addInfo('fa_member_rewards_ssssjbl',array('member_id'=>$member_id,'cz'=>$ssssj_cz,'hbcz'=>$ssssj_hbcz,'lw'=>-1,'wz'=>-1,'yp'=>-1,'sp'=>-1,'add_time'=>$ctime));
            }else{
                $IndexTableModel->editInfo('fa_member_rewards_ssssjbl',"`member_id` = '{$member_id}'",array('cz'=>$ssssj_cz,'hbcz'=>$ssssj_hbcz,'lw'=>-1,'wz'=>-1,'yp'=>-1,'sp'=>-1,'add_time'=>$ctime));
            }
        }

        Db::commit(); // 提交事务
        $Redis_Lock->unlock($otc_sell_key);    //释放锁
        return admin_success('调整用户返利比例配置成功',URL_CLOSE_REFRESH);
    }



}
